package com.example.c5c6;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

public class ServletConfigTest extends HttpServlet {
    private ServletConfig config;
    public ServletConfigTest(){
        super();
    }
    @Override
    public void destroy(){
        super.destroy();
    }
    @Override
    public void init() throws ServletException {
        super.init();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String charset =this.config.getInitParameter("charset");
        response.setCharacterEncoding(charset);
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
        out.println("<HTML>");
        out.println("<HEAD><TITLE>ServletConfig</TITLE></HEAD>");
        out.println("<BODY>");
       out.println("获取lnitParamServlet的初始化参数\"encoding\"的字符串值:"+charset);
        out.println("</table>");
        out.println("</BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
